package com.shujia.spark

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Demo12mapValues {
  def main(args: Array[String]): Unit = {
    val conf: SparkConf = new SparkConf()
      .setAppName("make")
      .setMaster("local")


    val sc = new SparkContext(conf)

    val scoreRDD: RDD[String] = sc.textFile("spark/data/score.txt")


    val kvRDD: RDD[(String, Int)] = scoreRDD.map(score => {
      val split: Array[String] = score.split(",")
      val id: String = split(0)
      val sco: Int = split(2).toInt
      (id, sco)
    })

    val rdd2: RDD[(String, Int)] = kvRDD.map(kv => (kv._1, kv._2 * 2))

    rdd2.foreach(println)

    val rdd3: RDD[(String, Int)] = kvRDD.mapValues(sco => sco * 2)


    rdd3.foreach(println)
  }

}
